﻿using System;
using System.Collections.Concurrent;

namespace Builder
{
    public enum STATUS_TYPE
    {
        异常,
        运行,
        停止
    }

    public class BuilderStatus
    {
        private static BuilderStatus bs;
        public static ConcurrentDictionary<string, string> EquipmentState = new ConcurrentDictionary<string, string>();
        public const string STATUS_GROUP_PLC = "PLC运行状态：";
        //public const string STATUS_GROUP_LEFTGPS = "Left_GPS运行状态：";
        //public const string STATUS_GROUP_RIGHTGPS = "Right_GPS运行状态：";
        public const string ITEM_LRS_LEFT = "Left_LRS运行状态：";
        public const string ITEM_LRS_RIGHT = "Right_LRS运行状态：";
        public const string ITEM_LRS_Third = "Third_LRS运行状态：";
        public const string STATUS_South_3D_DB = "取料PostgreSql运行状态：";
        public const string STATUS_North_3D_DB = "堆料PostgreSql运行状态：";
        public const string STATUS_Auto_3D_DB = "自动化PostgreSql运行状态：";
        //public const string STATUS_GROUP_DIG_DB = "SQLSever链接状态：";
        //public const string STATUS_GROUP_Incli = "倾角仪连接状态: ";

        public const string ITEM_Flow_3D_DB = "流量监测PostgreSql运行状态：";
        public const string ITEM_WCS_BQ = "取料WCS连接状态: ";
        public const string ITEM_WCS_BD = "堆料WCS连接状态: ";
        public const string ITEM_TEMP_CONN = "感温电缆连接状态: ";
        public const string ITEM_GAS_CONN = "可燃气体报警器连接状态: ";

        private const string STATUS_TYPE_STOP = "停止";
        private const string STATUS_TYPE_START = "运行";
        private const string STATUS_TYPE_ERROR = "异常";

        public static bool plcPower = false;

        public static bool UDPReceiveType = false;
        private BuilderStatus()
        {
            //EquipmentState.TryAdd(STATUS_GROUP_PLC, STATUS_TYPE_STOP);
            //EquipmentState.TryAdd(STATUS_GROUP_LEFTGPS, STATUS_TYPE_STOP);
            //EquipmentState.TryAdd(STATUS_GROUP_RIGHTGPS, STATUS_TYPE_STOP);
            //EquipmentState.TryAdd(STATUS_South_3D_DB, STATUS_TYPE_STOP);
            //EquipmentState.TryAdd(STATUS_North_3D_DB, STATUS_TYPE_STOP);
            //EquipmentState.TryAdd(STATUS_Auto_3D_DB, STATUS_TYPE_STOP);
            //EquipmentState.TryAdd(STATUS_GROUP_DIG_DB, STATUS_TYPE_STOP);
            //EquipmentState.TryAdd(STATUS_GROUP_Incli, STATUS_TYPE_STOP);
            //EquipmentState.TryAdd(ITEM_LRS_LEFT, STATUS_TYPE_STOP);
            //EquipmentState.TryAdd(ITEM_LRS_RIGHT, STATUS_TYPE_STOP);
            //EquipmentState.TryAdd(ITEM_LRS_Third, STATUS_TYPE_STOP);
            //EquipmentState.TryAdd(ITEM_Flow_3D_DB, STATUS_TYPE_STOP);
            //EquipmentState.TryAdd(ITEM_WCS_BQ, STATUS_TYPE_STOP);
            //EquipmentState.TryAdd(ITEM_WCS_BD, STATUS_TYPE_STOP);
            EquipmentState.TryAdd(ITEM_TEMP_CONN, STATUS_TYPE_STOP);
            //EquipmentState.TryAdd(ITEM_GAS_CONN, STATUS_TYPE_STOP);
        }

        public static void SetStatus(string equipItem, STATUS_TYPE sTATUS_TYPE)
        {
            EquipmentState[equipItem] = sTATUS_TYPE.ToString();
        }

        public static void SetStart(string equipItem)
        {
            EquipmentState[equipItem] = STATUS_TYPE_START;
        }

        public static void SetStop(string equipItem)
        {
            EquipmentState[equipItem] = STATUS_TYPE_ERROR;
        }

        public static void SetError(string equipItem)
        {
            EquipmentState[equipItem] = STATUS_TYPE_ERROR;
        }

        //public static int STATUS_LRS_Third
        //{
        //    get
        //    {
        //        return GetEquipmentState(ITEM_LRS_Third);
        //    }
        //    set
        //    {
        //        SetEquipmentState(ITEM_LRS_Third, value.ToString());
        //    }
        //}

        //public static int STATUS_LRS_RIGHT
        //{
        //    get
        //    {
        //        return GetEquipmentState(ITEM_LRS_RIGHT);
        //    }
        //    set
        //    {
        //        SetEquipmentState(ITEM_LRS_RIGHT, value.ToString());
        //    }
        //}

        //public static int STATUS_LRS_LEFT
        //{
        //    get
        //    {
        //        return GetEquipmentState(ITEM_LRS_LEFT);
        //    }
        //    set
        //    {
        //        SetEquipmentState(ITEM_LRS_LEFT, value.ToString());
        //    }
        //}

        public static int STATUS_WCS_BQ
        {
            get
            {
                return GetEquipmentState(ITEM_WCS_BQ);
            }
            set
            {
                SetEquipmentState(ITEM_WCS_BD, value.ToString());
            }
        }

        public static int STATUS_WCS_BD
        {
            get
            {
                return GetEquipmentState(ITEM_WCS_BD);
            }
            set
            {
                SetEquipmentState(ITEM_WCS_BD, value.ToString());
            }
        }

        private static int GetEquipmentState(string _STATUS_ITEM)
        {
            if (!EquipmentState.ContainsKey(_STATUS_ITEM))
                return 0;

            switch (EquipmentState[_STATUS_ITEM])
            {
                default:
                case STATUS_TYPE_ERROR:
                    return 0;

                case STATUS_TYPE_START:
                    return 1;

                case STATUS_TYPE_STOP:
                    return 2;
            }
        }

        private static void SetEquipmentState(string _STATUS_ITEM, string state)
        {
            EquipmentState[_STATUS_ITEM] = state;
        }
    }
}
